package lanou.autohome.findcar.adapters;


import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.HashMap;

import lanou.autohome.R;
import lanou.autohome.basetool.NetTool;

public class BrandHeaderDownSectionedAdapter extends SectionedBaseAdapter {

    private Context mContext;
    private NetTool mNetTool;
    private ArrayList<ArrayList<String>> nameAll;
    private ArrayList<HashMap<String, String>> urlAll;
    private String[] order = {"A" ,"B" ,"C" ,"D" ,"F" ,"G" ,"H" ,"J" ,"K" ,"L" ,
            "M" ,"N" ,"O" ,"P" ,"Q" ,"R" ,"S" ,"T" ,"W" ,"X" ,"Y" ,"Z" };
    public void setNameAll(ArrayList<ArrayList<String>> nameAll) {
        this.nameAll = nameAll;
        notifyDataSetChanged();
    }

    public void setUrlAll(ArrayList<HashMap<String, String>> urlAll) {
        this.urlAll = urlAll;
        notifyDataSetChanged();
    }

    public BrandHeaderDownSectionedAdapter(Context context) {
        this.mContext = context;
    }


    public void setmNetTool(NetTool mNetTool) {
        this.mNetTool = mNetTool;
    }

    @Override
    public Object getItem(int section, int position) {
        return nameAll.get(section).get(position);
    }

    @Override
    public long getItemId(int section, int position) {
        return position;
    }

    @Override
    public int getSectionCount() {
        return order.length;
    }

    @Override
    public int getCountForSection(int section) {

        return nameAll.get(section).size();
    }

    @Override
    public View getItemView(final int section, final int position, View convertView, ViewGroup parent) {
        NetTool mNetTool = new NetTool();
        RelativeLayout layout = null;
        if (convertView == null) {
            LayoutInflater inflator = (LayoutInflater) parent.getContext()
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            layout = (RelativeLayout) inflator.inflate(R.layout.item_findcar_brand_lvheaddown, null);
        } else {
            layout = (RelativeLayout) convertView;
        }

        ((TextView) layout.findViewById(R.id.text_lvhead_findcar_brand_item)).setText(nameAll.get(section).get(position));
                String url = urlAll.get(section).get(nameAll.get(section).get(position));
        mNetTool.getImage(url , (ImageView)layout.findViewById(R.id.image_lvhead_findcar_brand_item));
        return layout;
    }

    @Override
    public View getSectionHeaderView(int section, View convertView, ViewGroup parent) {
        ViewHolder viewHolder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_findcar_brand_lvtvheaddown, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.textView.setText(order[section]);
        return convertView;
    }

    private class ViewHolder {
        TextView textView;
        public ViewHolder(View view) {
            textView = (TextView) view.findViewById(R.id.text_lvtvhead_findcar_brand_item);
        }
    }
}
